package com.hjm.project.message.message.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.message.message.domain.MessgaeInfo;
import com.hjm.project.message.message.service.IMessgaeInfoService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 消息列Controller
 * 
 * @author wdw
 * @date 2020-11-26
 */
@Controller
@RequestMapping("/message/message")
public class MessgaeInfoController extends BaseController
{
    private String prefix = "message/message";

    @Autowired
    private IMessgaeInfoService messgaeInfoService;

    @RequiresPermissions("message:message:view")
    @GetMapping()
    public String message()
    {
        return prefix + "/message";
    }

    /**
     * 查询消息列列表
     */
    @RequiresPermissions("message:message:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MessgaeInfo messgaeInfo)
    {
        startPage();
        List<MessgaeInfo> list = messgaeInfoService.selectMessgaeInfoList(messgaeInfo);
        return getDataTable(list);
    }

    /**
     * 导出消息列列表
     */
    @RequiresPermissions("message:message:export")
    @Log(title = "消息列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MessgaeInfo messgaeInfo)
    {
        List<MessgaeInfo> list = messgaeInfoService.selectMessgaeInfoList(messgaeInfo);
        ExcelUtil<MessgaeInfo> util = new ExcelUtil<MessgaeInfo>(MessgaeInfo.class);
        return util.exportExcel(list, "message");
    }

    /**
     * 新增消息列
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存消息列
     */
    @RequiresPermissions("message:message:add")
    @Log(title = "消息列", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MessgaeInfo messgaeInfo)
    {
        return toAjax(messgaeInfoService.insertMessgaeInfo(messgaeInfo));
    }

    /**
     * 修改消息列
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        MessgaeInfo messgaeInfo = messgaeInfoService.selectMessgaeInfoById(id);
        mmap.put("messgaeInfo", messgaeInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存消息列
     */
    @RequiresPermissions("message:message:edit")
    @Log(title = "消息列", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MessgaeInfo messgaeInfo)
    {
        return toAjax(messgaeInfoService.updateMessgaeInfo(messgaeInfo));
    }

    /**
     * 删除消息列
     */
    @RequiresPermissions("message:message:remove")
    @Log(title = "消息列", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(messgaeInfoService.deleteMessgaeInfoByIds(ids));
    }
}
